#! /bin/bash 
#SQOOP_HOME=/opt/cloudera/parcels/CDH-6.2.1-1.cdh6.2.1.p0.1425774/bin/sqoop
SQOOP_HOME=/usr/bin/sqoop
if [[ $1 == "" ]];then
   dt=`date -d '1 days ago' "+%Y-%m-%d"`
else
   dt=$1
fi

echo '========================================'
echo '==============开始全量导入==============='
echo '========================================'

# 1.客户静态信息表
/usr/bin/sqoop import "-Dorg.apache.sqoop.sqlitter.allow_text_sqlitter=true" \
--connect 'jdbc:mysql://106.75.33.59:3306/scrm?useUnicode=true&characterEncoding=UTF8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select * ,'${dt}' as dt from customer where 1=1 and \$CONDITIONS" \
--hcatalog-database zx_ods \
--hcatalog-table ods_customer_apply \
-m 1
wait

# 2.线索申诉信息表
/usr/bin/sqoop import "-Dorg.apache.sqoop.sqlitter.allow_text_sqlitter=true" \
--connect 'jdbc:mysql://106.75.33.59:3306/scrm?useUnicode=true&characterEncoding=UTF8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select * ,'${dt}' as dt from customer_appeal where 1=1 and \$CONDITIONS" \
--hcatalog-database zx_ods \
--hcatalog-table ods_customer_appeal_apply \
-m 1
wait

# 3.客户线索表
/usr/bin/sqoop import "-Dorg.apache.sqoop.sqlitter.allow_text_sqlitter=true" \
--connect 'jdbc:mysql://106.75.33.59:3306/scrm?useUnicode=true&characterEncoding=UTF8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select * ,'${dt}' as dt from customer_clue where 1=1 and \$CONDITIONS" \
--hcatalog-database zx_ods \
--hcatalog-table ods_customer_clue_apply \
-m 1
wait

# 4.客户意向表
/usr/bin/sqoop import "-Dorg.apache.sqoop.sqlitter.allow_text_sqlitter=true" \
--connect 'jdbc:mysql://106.75.33.59:3306/scrm?useUnicode=true&characterEncoding=UTF8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select * ,'${dt}' as dt from customer_relationship where 1=1 and \$CONDITIONS" \
--hcatalog-database zx_ods \
--hcatalog-table ods_customer_relationship_apply \
-m 1
wait

# 5.员工信息表
/usr/bin/sqoop import "-Dorg.apache.sqoop.sqlitter.allow_text_sqlitter=true" \
--connect 'jdbc:mysql://106.75.33.59:3306/scrm?useUnicode=true&characterEncoding=UTF8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select * from employee where 1=1 and \$CONDITIONS" \
--hcatalog-database zx_ods \
--hcatalog-table ods_employee_apply \
-m 1
wait

# 6.班级信息表
/usr/bin/sqoop import "-Dorg.apache.sqoop.sqlitter.allow_text_sqlitter=true" \
--connect 'jdbc:mysql://106.75.33.59:3306/scrm?useUnicode=true&characterEncoding=UTF8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select * from itcast_clazz where 1=1 and \$CONDITIONS" \
--hcatalog-database zx_ods \
--hcatalog-table ods_itcast_clazz_apply \
-m 1
wait

# 7.校区信息表
/usr/bin/sqoop import "-Dorg.apache.sqoop.sqlitter.allow_text_sqlitter=true" \
--connect 'jdbc:mysql://106.75.33.59:3306/scrm?useUnicode=true&characterEncoding=UTF8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select * from itcast_school where 1=1 and \$CONDITIONS" \
--hcatalog-database zx_ods \
--hcatalog-table ods_itcast_school_apply \
-m 1
wait

# 8.学科信息表
/usr/bin/sqoop import "-Dorg.apache.sqoop.sqlitter.allow_text_sqlitter=true" \
--connect 'jdbc:mysql://106.75.33.59:3306/scrm?useUnicode=true&characterEncoding=UTF8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select * from itcast_subject where 1=1 and \$CONDITIONS" \
--hcatalog-database zx_ods \
--hcatalog-table ods_itcast_subject_apply \
-m 1
wait

# 9.员工部门表
/usr/bin/sqoop import "-Dorg.apache.sqoop.sqlitter.allow_text_sqlitter=true" \
--connect 'jdbc:mysql://106.75.33.59:3306/scrm?useUnicode=true&characterEncoding=UTF8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select * from scrm_department where 1=1 and \$CONDITIONS" \
--hcatalog-database zx_ods \
--hcatalog-table ods_scrm_department_apply \
-m 1
wait

echo '========================================'
echo '=================success==============='
echo '========================================'